home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / misc / math / MathFX_src.lha / Amiga.c next >
C/C++ Source or Header  |  1996-06-18  |  8KB  |  348 lines

  1. #include "mathfx.h"
  2. #include <dos.h>
  3. #include <stdio.h>
  4. #include <exec/types.h>
  5. #include <exec/ports.h>
  6. #include <graphics/display.h>
  7. #include <intuition/intuition.h>
  8. #include <intuition/intuitionbase.h>
  9. #include <pragmas/intuition_pragmas.h>
  10. #include <intuition/screens.h>
  11.  
  12. /* New requesters in v1.2 */
  13.  
  14. struct EasyStruct abortReq={
  15.     sizeof (struct EasyStruct),
  16.     0,
  17.     "MathFX Request",
  18.     "Abort current plot?",
  19.     "Yes|No",
  20. };
  21.  
  22. struct EasyStruct clrscreenReq={
  23.     sizeof(struct EasyStruct),
  24.     0,
  25.     "MathFX Request",
  26.     "Clear Screen?",
  27.     "Yes|No",
  28. };
  29.  
  30. struct NewScreen NewScreen = {
  31.    0,        /* LeftEdge Position */
  32.    0,        /* TopEdge */
  33.    640,        /* Width (high-res) */
  34.    400,        /* Height (interlace) */
  35.    1,        /* Depth (1 color) */
  36.    0,1,        /* DetailPen and BlockPen */
  37.    HIRES|INTERLACE,
  38.    CUSTOMSCREEN,
  39.    NULL,        /* Use default font */
  40.    NULL,        /* Don't want a title */
  41.    NULL,        /* Gadgets?? */
  42.    NULL        /* No CustomBitMap */
  43. };
  44.     
  45. struct NewWindow NewWindow = {
  46.    0,0,640,400,
  47.    -1,-1,
  48.    MENUPICK|VANILLAKEY,
  49.    SMART_REFRESH|BACKDROP|BORDERLESS|ACTIVATE,
  50.    NULL,    /* Window Gadget Pointer */
  51.    NULL,    /* Checkmark image */
  52.    NULL,    /* No Title */
  53.    NULL,    /* My Screen Pointer (this is set below) */
  54.    NULL, /* Not a SuperBitMap */
  55.    0,0,0,0,
  56.    CUSTOMSCREEN
  57. };
  58.  
  59. struct IntuiText IText[] = {
  60.    { 0, 1, JAM1, 0, 0, NULL, "Screen to Back" },
  61.    { 0, 1, JAM1, 0, 0, NULL, "Clear Screen" },
  62.    { 0, 1, JAM1, 0, 0, NULL, "Close Screen" },
  63.    { 0, 1, JAM1, 0, 0, NULL, "Break  (CTRL-C)"},
  64.    { 0, 1, JAM1, 0, 0, NULL, "Continue   (RETURN/ENTER)"}
  65. };
  66.  
  67. struct MenuItem MenuItem[] = {
  68.    {
  69.       &MenuItem[1],
  70.       0, 0, (140 + COMMWIDTH), 9,
  71.       ITEMTEXT | COMMSEQ | ITEMENABLED | HIGHCOMP,
  72.       0,
  73.       (APTR)&IText[0],
  74.       NULL,
  75.       'F',
  76.       NULL,
  77.       NULL
  78.    },
  79.    {
  80.       &MenuItem[2],
  81.       0, 9, (140 + COMMWIDTH), 9,
  82.       ITEMTEXT | COMMSEQ | HIGHCOMP,
  83.       0,
  84.       (APTR)&IText[1],
  85.       NULL,
  86.       'C',
  87.       NULL,
  88.       NULL
  89.    },
  90.    {
  91.       NULL,
  92.       0, 18, (140 + COMMWIDTH), 9,
  93.       ITEMTEXT | COMMSEQ | HIGHCOMP,
  94.       0,
  95.       (APTR)&IText[2],
  96.       NULL,
  97.       'Q',
  98.       NULL,
  99.       NULL
  100.    },
  101.    {
  102.       &MenuItem[4],
  103.       0, 0, (140 + COMMWIDTH), 9,
  104.       ITEMTEXT | ITEMENABLED | HIGHCOMP,
  105.       0,
  106.       (APTR)&IText[3],
  107.       NULL,
  108.       NULL,
  109.       NULL,
  110.       NULL
  111.    },
  112.    {
  113.       NULL,
  114.       0, 9, (140 + COMMWIDTH), 9,
  115.       ITEMTEXT | HIGHCOMP,
  116.       0,
  117.       (APTR)&IText[4],
  118.       NULL,
  119.       NULL,
  120.       NULL,
  121.       NULL
  122.    }
  123. };
  124.     
  125. struct Menu Menu[] = {
  126.    {
  127.       &Menu[1],
  128.       0, 0, 140, 0,
  129.       MENUENABLED,
  130.       "Screen Control",
  131.       &MenuItem[0]
  132.    },        
  133.    {
  134.       NULL,
  135.       140, 0, 140, 0,
  136.       MENUENABLED,
  137.       "Drawing Control",
  138.       &MenuItem[3]
  139.    }
  140. };
  141.  
  142. /* extern long IntuitionBase; */
  143. extern long GfxBase;
  144. static struct Screen *Screen;
  145. static struct Window *Window;
  146. static struct Border Border;
  147. static short xy[4];
  148.  
  149. int reqresult; /* Requester result */
  150.  
  151. /* Open Borderless Full Screen Window for Drawing */
  152. void amiini()
  153. {
  154. /*   LONG OpenLibrary(), OpenScreen(), OpenWindow(); */ /* Redundant for SAS */
  155.  
  156.    IntuitionBase = OpenLibrary("intuition.library",0);
  157.    if(IntuitionBase == NULL) {
  158.       printf("Couldn't open intuition.library");
  159.       exit(1);
  160.    }
  161.     
  162.    GfxBase = OpenLibrary("graphics.library",0);
  163.    if(GfxBase == NULL) {
  164.       printf("Couldn't open graphics.library");
  165.       exit(1);
  166.    }
  167.     
  168.    if((Screen = (struct Screen *)OpenScreen(&NewScreen)) == NULL) {
  169.       printf("Couldn't open custom screen");
  170.       exit(1);
  171.    }
  172.     
  173.    ShowTitle(Screen,FALSE);
  174.  
  175.    NewWindow.Screen = Screen;    /* Pointer to CustomScreen */
  176.     
  177.    if((Window = (struct Window *)OpenWindow(&NewWindow)) == NULL) {
  178.       printf("Couldn't open window.\n");
  179.       exit(1);
  180.    }
  181.     
  182.    Border.LeftEdge = 0;
  183.    Border.TopEdge = 0;
  184.    Border.FrontPen = 1;
  185.    Border.BackPen = 0;
  186.    Border.DrawMode = JAM1;
  187.    Border.Count = 2;
  188.    Border.NextBorder = NULL;
  189.    Border.XY = xy;
  190.     
  191.    SetMenuStrip(Window,Menu);
  192. }
  193.  
  194. void amitex()
  195. {
  196.    /* I don't have a text mode on the custom screen */
  197. }
  198.  
  199. void amigra()
  200. {
  201. }
  202.  
  203. void amicol(color)
  204. int color;
  205. {
  206.    /* No color support at present -- maybe in the next release */
  207. }
  208.  
  209. /* Clear the screen */
  210. void amiclr()
  211. {
  212.    SetRast(Window->RPort,0);
  213. }        
  214.  
  215. /* Draw the line.  Also check for interrupts. */
  216. void amilin(x1,y1,x2,y2)
  217. int x1, y1, x2, y2;
  218. {
  219.    int ItemNumber, MenuNumber;
  220.    ULONG class;
  221.    USHORT code, qualifier;
  222.    struct IntuiMessage *message;
  223.    struct MenuItem *Item, *ItemAddress();
  224.     struct Message *GetMsg();
  225.    void beepw();
  226.  
  227.    xy[0] = x1;
  228.    xy[1] = 399-y1;
  229.    xy[2] = x2;
  230.    xy[3] = 399-y2;
  231.     
  232.    if((xy[0] == xy[2]) && (xy[1] == xy[3]))
  233.       WritePixel(Window->RPort,xy[0],xy[1]);
  234.    else
  235.       DrawBorder(Window->RPort,&Border,0,0);
  236.     
  237.    /* Check for user abort via CTRL-C or menu ABORT selection */
  238.    /* and also Screen to Back Selection */
  239.    /* All other messages are replied to but ignored. */
  240.    while((message = (struct IntuiMessage *)
  241.                      GetMsg(Window->UserPort))!=NULL) {
  242.       class = message->Class;
  243.       code = message->Code;
  244.       qualifier = message->Qualifier;
  245.       ReplyMsg(message);
  246.       if(class == VANILLAKEY) {
  247.          if(code == 3)
  248.             beepw();
  249.       }
  250.       else if(class == MENUPICK) {
  251.          while (code != MENUNULL) {
  252.                Item = ItemAddress(Menu,code);
  253.             MenuNumber = MENUNUM(code);
  254.             ItemNumber = ITEMNUM(code);
  255.             if((MenuNumber == 0) && (ItemNumber == 0))
  256.                ScreenToBack(Screen);
  257.             else if((MenuNumber == 1) && (ItemNumber == 0))
  258.                beepw();
  259.             code = Item->NextSelect;
  260.          }
  261.       }
  262.    }
  263. }
  264.  
  265. void amitid()
  266. {
  267.    ClearMenuStrip(Window);
  268.    CloseWindow(Window);
  269.    CloseScreen(Screen);
  270.    return;
  271. }
  272.  
  273. void beepw()
  274. {
  275.    int ItemNumber, MenuNumber;
  276.    ULONG class;
  277.    USHORT code, qualifier;
  278.    struct IntuiMessage *message;
  279.    struct MenuItem *Item, *ItemAddress();
  280.     struct Message *GetMsg();
  281.  
  282.    OnMenu(Window,SHIFTMENU(0)+SHIFTITEM(1));
  283.    OnMenu(Window,SHIFTMENU(0)+SHIFTITEM(2));
  284.    OnMenu(Window,SHIFTMENU(1)+SHIFTITEM(1));
  285.    OffMenu(Window,SHIFTMENU(1)+SHIFTITEM(0));
  286.    for(;;) {
  287.       Wait(1L << Window->UserPort->mp_SigBit);
  288.       while((message = (struct IntuiMessage *)
  289.                         GetMsg(Window->UserPort))!=NULL) {
  290.          class = message->Class;
  291.          code = message->Code;
  292.          qualifier = message->Qualifier;
  293.          ReplyMsg(message);
  294.          if(class == VANILLAKEY) {
  295.             if(code == 13) {
  296.                OffMenu(Window,SHIFTMENU(0)+SHIFTITEM(1));
  297.                OffMenu(Window,SHIFTMENU(0)+SHIFTITEM(2));
  298.                OffMenu(Window,SHIFTMENU(1)+SHIFTITEM(1));
  299.                OnMenu(Window,SHIFTMENU(1)+SHIFTITEM(0));
  300.                return;
  301.             }
  302.          }
  303.          else if(class == MENUPICK) {
  304.             while (code != MENUNULL) {
  305.                Item = ItemAddress(Menu,code);
  306.                MenuNumber = MENUNUM(code);
  307.                ItemNumber = ITEMNUM(code);
  308.                if(MenuNumber == 0) {
  309.                   if(ItemNumber == 0)
  310.                      ScreenToBack(Screen);
  311.                   else if(ItemNumber == 1) {
  312.                      reqresult=EasyRequest(NULL,&clrscreenReq,0,"MathFX Request");
  313.                      if (reqresult==1){
  314.                           SetRast(Window->RPort,0); reqresult=0;
  315.                         }
  316.                      else
  317.                         reqresult=0;
  318.                     }
  319.                   else if(ItemNumber == 2) {
  320.                      reqresult=EasyRequest(NULL,&abortReq,0,"MathFX Request");
  321.                      if (reqresult==1){
  322.                         fxend();
  323.                         ClearMenuStrip(Window);
  324.                         CloseWindow(Window);
  325.                         CloseScreen(Screen);
  326.                         exit(1);
  327.                      }
  328.                      else
  329.                         reqresult=0;
  330.                      }
  331.                }
  332.                else if(MenuNumber == 1) {
  333.                   if (ItemNumber == 1) {
  334.                      OffMenu(Window,SHIFTMENU(0)+SHIFTITEM(1));
  335.                      OffMenu(Window,SHIFTMENU(0)+SHIFTITEM(2));
  336.                      OffMenu(Window,SHIFTMENU(1)+SHIFTITEM(1));
  337.                      OnMenu(Window,SHIFTMENU(1)+SHIFTITEM(0));
  338.                      return;
  339.                   }
  340.                }
  341.                code = Item->NextSelect;
  342.             }
  343.          }
  344.       }
  345.    }
  346.  
  347. };
  348.